import React,{ useEffect, useState } from 'react'
import Taro, { useDidShow } from '@tarojs/taro'
import { View, Text,Image,Button,ContactButton } from '@tarojs/components'
import "taro-ui/dist/style/components/icon.scss";
import './index.less'

export default function Mine() {
  let capsule = {}
  if(process.env.TARO_ENV === 'weapp') capsule = Taro.getMenuButtonBoundingClientRect()

  const [userinfo,setUserInfo] = useState({})
  const [couponNum,setCouponNum] = useState(0)
  const [loginTxt,setLoginTxt] = useState('登录/注册')
  useDidShow(()=>{
    Taro.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000008'
    })
    Taro.$setTabbarList()
    setUserInfo(Taro.getStorageSync('user') || {})
    Taro.$get("/wallet/event/voucher/getCount").then(res=>{
      if(res.code == '1') setCouponNum(res.content || 0)
    })
    if(process.env.TARO_ENV === 'tt'){
      setLoginTxt('抖音登录/注册')
    }
  })
  const handleToUrl = (url)=>{  //  跳转路由
    Taro.navigateTo({
      url
    })
  }
  const handleToOrder = e=>{
    Taro.verifyLogin()
    Taro.navigateTo({
      url:`/orderSubPack/order-list/index?status=${e}`
    })
  }
  function handleAccount(){
    if(process.env.TARO_ENV == 'h5'){
      location.href = 'https://mp.weixin.qq.com/s?__biz=MzkzNzUyMDYxOA==&mid=2247483673&idx=1&sn=e1695175608153b883b47cb69f2c7d3b&chksm=c28f7d9cf5f8f48abc68ef87d4dd45969cd531ca2648ce553dfc9d94691c1a1902abcfb253ce#rd'
      return;
    }
    Taro.navigateTo({
      url:`/pages/fineEngine/webView?url=${encodeURIComponent('https://mp.weixin.qq.com/s?__biz=MzkzNzUyMDYxOA==&mid=2247483673&idx=1&sn=e1695175608153b883b47cb69f2c7d3b&chksm=c28f7d9cf5f8f48abc68ef87d4dd45969cd531ca2648ce553dfc9d94691c1a1902abcfb253ce#rd')}`
    })
  }
  
  return (
    <View className="mine">
      <View className="mine-header">
        {userinfo?.userId?
        <View className="header-box" onClick={()=>{handleToUrl('/mineSubPack/information/index')}}>
          <Image className="header-img" src={userinfo.avatar} mode="aspectFill"></Image>
          <View className="header-title">
            <View className='h2'>{userinfo.nickName}</View>
            <View style={{marginTop: '8px'}} className='p'>在大银幕下，为支持的战队呐喊！</View>
          </View>
          <Image className="header-icon" src={require('@/images/setting.svg')} mode="aspectFill"></Image>
        </View>:
        <View className="header-box" v-else onClick={()=>{handleToUrl('/pages/other/login/index')}}>
          <Image className="header-img" src={require('@/images/avatar.png')} mode="aspectFill"></Image>
          <View className='p'>{loginTxt}</View>
        </View>}
      </View>
      <View className="mine-order">
        <View className="order-title">
          <View className='h3'>我的订单</View>
          <View onClick={()=>{handleToOrder(0)}} className='p'>查看全部订单 <Text className='at-icon at-icon-chevron-right'></Text></View>
        </View>
        <View className="order-list" onClick={()=>{handleToOrder(1)}}>
          <View className="list-item">
            <Image src={require('@/images/unpaid.svg')} className="item-icon"></Image>
            <View className='p'>待付款</View>
          </View>
          <View className="list-item" onClick={()=>{handleToOrder(3)}}>
            <Image src={require('@/images/tobeused.svg')} className="item-icon"></Image>
            <View className='p'>待收货/使用</View>
          </View>
          <View className="list-item" onClick={()=>{handleToOrder(4)}}>
            <Image src={require('@/images/tobeevaluated.svg')} className="item-icon"></Image>
            <View className='p'>待评价</View>
          </View>
          <View className="list-item" onClick={()=>{handleToOrder(5)}}>
            <Image src={require('@/images/aftersale.svg')} className="item-icon"></Image>
            <View className='p'>退款/售后</View>
          </View>
        </View>
      </View>
      <View className="mine-wallet">
        <View className="wallet-item box-border">
          <Image src={require('@/images/wallet.svg')} className="item-icon"></Image>
          <View className='p'>我的钱包</View>
        </View>
        <View className="wallet-item" onClick={()=>{handleToUrl('/mineSubPack/mine-integral/index')}}>
          <View className='h3'>0</View>
          <View className='p'>积分</View>
        </View>
        <View className="wallet-item" onClick={()=>{handleToUrl('/mineSubPack/mine-coupon/index')}}>
          <View className='h3'>{couponNum}</View>
          <View className='p'>优惠券</View>
        </View>
        <View className="wallet-item" onClick={()=>{handleToUrl('/mineSubPack/card-list/index')}}>
          <View className='h3'>0 <Text style={{fontSize: '24rpx',marginLeft: '8rpx'}}>元</Text></View>
          <View className='p'>储值卡</View>
        </View>
      </View>
      <View className="mine-tools">
        <View className="tools-item" onClick={()=>{
          Taro.verifyLogin()
          Taro.navigateTo({
            url:'/mineSubPack/wholeCinema/operWholeCinema/index'
          })
        }}>
          <Image src={require('@/images/publish.svg')} className="item-icon"></Image>
          <View className='p'>云包场</View>
        </View>
        {/* <View className="tools-item" onClick={()=>{handleToUrl('/mineSubPack/activity/start/index')}}>
          <Image src={require('@/images/publish.svg')} className="item-icon"></Image>
          <View className='p'>活动开团</View>
        </View> */}
        {/* <View className="tools-item">
          <Image src={require('@/images/publish.svg')} className="item-icon"></Image>
          <View className='p'>影院接团</View>
        </View> */}
        <View className="tools-item" onClick={()=>{handleToUrl('/mainPages/watch-list/index')}}>
          <Image src={require('@/images/buyer.svg')} className="item-icon"></Image>
          <View className='p'>常用购票人</View>
        </View>
        <View className="tools-item" onClick={()=>{handleToUrl('/giftCardSubPack/address/index')}}>
          <Image src={require('@/images/waitingfordelivery.svg')} className="item-icon"></Image>
          <View className='p'>收货地址</View>
        </View>
        <View className="tools-item" onClick={()=>{handleAccount()}}>
          <Image src={require('@/images/offical_wechat.svg')} className="item-icon"></Image>
          <View className='p'>关注公众号</View>
        </View>
        <Button className="tools-item" open-type="contact">
          <Image src={require('@/images/service.svg')} className="item-icon"></Image>
          <View className='p'>在线客服</View>
        </Button>
      </View>
    </View>
  )
}